<?php
// 本文档自动生成，仅供测试运行
class IndexAction extends Action
{
    
    /**
    +----------------------------------------------------------
    * 默认后台地址
    +----------------------------------------------------------
    */
    public function index()
    {
    	if(isset($_SESSION['adm_name']) and isset($_SESSION['isAdmin']) ){
			$this->display();
		}else {
			$this->redirect('Index/login');
		}   
    }
    /**
    +----------------------------------------------------------
    * 头部
    +----------------------------------------------------------
    */
    public function head()
    {
    	
        $this->display();
    }
	
	function main(){
	    echo phpinfo();
	
	} 
    
    /**
     +----------------------------------------------------------
     * 登录
     +----------------------------------------------------------
    */
    public function login(){
    	$this->assign('pagetitle', '后台管理系统');
    	$this->display();
    }
    

    /*验证码	---index/login*/
    public function vdcode(){
    	$type	 =	 isset($_GET['type'])?$_GET['type']:'gif';
        import("ORG.Util.Image");
        Image::buildImageVerify(5,1,$type);
    }
    
    public function cheklogin(){
    	if(''==$_POST['adm_name']){
    		$this->error('用户名为空！');
    	}elseif (''==$_POST['pass']){
    		$this->error('密码为空！');
    	}elseif (''==$_POST['vdcode']){
    		$this->error('验证码为空！');
    	}elseif (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}elseif ($_SESSION['verify'] != md5($_POST['vdcode'])){
    		$this->error('验证码错！');
    	}else {
    		
    		$map['adm_name'] = t(h($_POST['adm_name']));
    		$res = M('admin')->where($map)->find();
    		
    		if($res){
    			
    			if( $res['passwd'] == md5($_POST['pass'])){
    				$res['isAdmin']	= 1;
    				$_SESSION = $res;
					//LOG
    				$datalog = "用户 {$_SESSION['adm_name']} 于".date('Y-m-d H:i:s', time())."成功登录系统！使用IP:".get_client_ip();
    				ALOG(1, $datalog);
    				
    				$this->assign('waitSecond', 1);
    				$this->assign('jumpUrl', './admin.php');
    				$this->success("欢迎管理员:{$_SESSION['adm_name']}！");
    			}else {
//     				echo $res['passwd']; die;
    				$this->error("密码验证失败！");
    			}
    			
    		}else {
    			$this->error("无此用户！");
    		}
    	}
    }
    
    public function logout(){
    	import("ORG.Util.Session");
		$s = new Session();
		$s->destroy();
		
		$this->assign('jumpUrl', './');
		$this->success("已注销！");
    }
    
    
    
    
}
?>